package com.zyj.jetpackdemo
import android.app.Activity
import android.content.Intent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.zyj.jetpackdemo.ui.theme.MajorBlueColor

@Composable
fun MenuLists(items: List<String>, intent: Intent, activity: Activity) {
    LazyColumn(
        modifier = Modifier
            .fillMaxWidth(1.0f)
            .fillMaxHeight(1.0f)
            .background(color = MajorBlueColor)
            .padding(top = 16.dp, bottom = 16.dp),
        verticalArrangement = Arrangement.spacedBy(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        items(items.size) { index ->
            Card(
                modifier = Modifier
                    .fillMaxWidth(0.9f)
                    .height(50.dp)
                    .clickable {
                        jumpToActivity(index, intent, activity)
                    }
            ) {
                Text(
                    text = items[index],
                    modifier = Modifier
                        .fillMaxWidth(1.0f)
                        .fillMaxHeight(1.0f)
                        .wrapContentSize(align = Alignment.Center)
                )
            }
        }
    }
}


fun jumpToActivity(index: Int, intent: Intent, activity: Activity) {
    intent.putExtra(INTENT_DATA, index)
    activity.startActivity(intent)
}